﻿var commonFun = {};

commonFun.token = 'token';

// 写cookies
commonFun.setCookie = function (key, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = key + '=' + escape(value) + ((expiredays == null) ? '' : ';expires=' + exdate.toGMTString());
};

// 读cookies
commonFun.getCookie = function (key) {
    var arr, reg = new RegExp('(^| )' + key + '=([^;]*)(;|$)');
    arr = document.cookie.match(reg);
    return arr ? arr[2] : null;
};

// 删cookies
commonFun.delCookie = function (key) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = commonFun.getCookie(key);
    if (cval != null)
        document.cookie = key + '=' + cval + ';expires=' + exp.toGMTString();
};

// 关闭远程协助软件提醒
commonFun.createDialog = function (exeList) {
    var helpDialog = '<div class="modal fade" id="helpDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">'
        + '<div class="modal-dialog" role="document">'
        + '<div class="modal-content">'
        + '<div class="modal-header">'
        + '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>'
        + '<h4 class="modal-title">设备检测提示</h4>'
        + '</div>'
        + '<div class="modal-body">'
        + '<div class="runTip" style="padding:0 40px;">'
        + '<p style="font-size: 16px;line-height: 3em;color: #4E7ADD;">远程协助应用关闭提醒：</p>'
        + '<p style="font-size: 16px;line-height: 3em;color: #4E7ADD;">检测到您的设备上有' + exeList + '远程协助应用程序正在开启。</p>'
        + '<p style="font-size: 16px;line-height: 3em;color: #4E7ADD;">为保证考试顺利进行，请关闭这些应用程序后重新启动考试应用！</p>'
        + '</div>'
        + '</div>'
        + '<div class="modal-footer">'
        //+'<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>'
        + '<button type="button" class="btn btn-primary" data-dismiss="modal">确认</button>'
        + '</div>'
        + '</div>'
        + '</div>'
        + '</div>';
    $("body").append(helpDialog);
    $('#helpDialog').modal({
        keyboard: false,
        backdrop: 'static',
        show: true
    });
};

try {
    CSharpFunction.setEnableRefresh(true);// 启用/禁用浏览器右键刷新菜单
    CSharpFunction.setEnableSettingButton(false);// 启用/禁用设置按钮
    CSharpFunction.setQuitWithVerification(false);// 退出时是否需要验证
    //CSharpFunction.setEnableSuperPwd(true,'open');// 是否启用超级密码，密码是什么
} catch (err) {

}

commonFun.init = function () {
    try {
        // 判断是否运行远程协助软件
        var exeList = "";
        var exeArr = ['QQ.exe', 'TIM.exe', 'TightVNC.exe', 'TeamViewer.exe'];// 需要检测的应用集合
        $.each(exeArr, function (i, exe) {
            if (CSharpFunction.isRunning(exe)) {
                if (exeList != "") {
                    exeList += "、";
                }
                exeList += exe.split(".exe")[0];
            }
        });

        if (exeList != "") {
            commonFun.createDialog(exeList);
            return true;// 有远程软件在运行
        }
    }
    catch (err) {
        // 如果当前环境是开发和测试时，可使用浏览器进行考试
        if (_profile != "dev" && _profile != "test") {
            // 不在客户端,下载客户端
            window.location.href = "/Examinee/DownloadApp";
        }
    }
};
//commonFun.init();

